<template>
  <div class="execution">
    <basic-container>
      <div class="sw-revenue-daily-report">
        <el-form :inline="true">
          <el-form-item label="盘点日期">
            <span v-if="readonly || this.operationType === 'edit'">{{ reportData.statisticsDate | formatDate }}</span>
            <el-date-picker
              v-else
              v-model="initialStatisticsDate"
              type="month"
              value-format="yyyy-MM"
              placeholder="选择日期"
              @change="statisticsDateSelect"
            >
            </el-date-picker>
          </el-form-item>
          <table class="el-table el-table--border">
            <tr>
              <td class="bold center" width="180"></td>
              <td class="bold center" width="210">规格</td>
              <td class="bold center" width="210">部门配发数量</td>
              <td class="bold center" width="210">站间调配数量</td>
	      <td class="bold center" width="210">上交数量</td>
              <td class="bold center" width="210">数量</td>
              <td class="bold center" width="210">金额合计</td>
              <td class="bold center" width="210">实点数量</td>
              <td class="bold center" width="210">差异数量</td>
              <td class="bold center" width="400">原因</td>
            </tr>
            <tr v-if="readonly">
              <td rowspan="4" class="bold center">
                已使用
              </td>
              <td class="bold center" height="79">10 元</td>
              <td class="center">
                <span>{{ reportData.useTenDispatchNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenDeployNumber }}</span>
              </td>
	       <td class="center">
                <span>{{ reportData.useTenDeployCompleteNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenMoney.toFixed(2) }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenCheckNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenDiffNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTenDiffReason }}</span>
              </td>
            </tr>
            <tr v-if="readonly">
              <td class="bold center" height="79">20 元</td>
              <td class="center">
                <span>{{ reportData.useTwentyDispatchNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyDeployNumber }}</span>
              </td>
	      <td class="center">
                <span>{{ reportData.useTwentyDeployCompleteNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyMoney.toFixed(2) }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyCheckNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyDiffNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useTwentyDiffReason }}</span>
              </td>
            </tr>
            <tr v-if="readonly">
              <td class="bold center" height="79">50 元</td>
              <td class="center">
                <span>{{ reportData.useFiftiyDispatchNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyDeployNumber }}</span>
              </td>
	      <td class="center">
                <span>{{ reportData.useFiftiyDeployCompleteNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyMoney.toFixed(2) }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyCheckNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyDiffNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useFiftiyDiffReason }}</span>
              </td>
            </tr>
            <tr v-if="readonly">
              <td class="bold center" height="79">100 元</td>
              <td class="center">
                <span>{{ reportData.useHundredDispatchNumber }}</span>
              </td>
	      <td class="center">
                <span>{{ reportData.useHundredDeployNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredDeployCompleteNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredMoney.toFixed(2) }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredCheckNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredDiffNumber }}</span>
              </td>
              <td class="center">
                <span>{{ reportData.useHundredDiffReason }}</span>
              </td>
            </tr>
            <tr>
              <td rowspan="4" class="bold center">
                未使用
              </td>
              <td class="bold center" height="79">10 元</td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenDispatchNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenDispatchNumber"
                  :min="0"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleDeployCompleteNumberCalculate($event, 'ten')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenDeployNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenDeployNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
	      <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenDeployCompleteNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenDeployCompleteNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseNumberChange($event, 10, 'unuseTenMoney')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenMoney.toFixed(2) }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenMoney"
                  :step="0"
                  :precision="2"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenCheckNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenCheckNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseCheckNumberChange($event, 'ten')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenDiffNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTenDiffNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTenDiffReason }}</span>
                <el-input
                  v-else
                  type="textarea"
                  v-model="reportData.unuseTenDiffReason"
                  placeholder="请输入备注"
                  :disabled="readonly"
                />
              </td>
            </tr>
            <tr>
              <td class="bold center" height="79">20 元</td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyDispatchNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyDispatchNumber"
                  :min="0"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleDeployCompleteNumberCalculate($event, 'twenty')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyDeployNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyDeployNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
	       <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyDeployCompleteNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyDeployCompleteNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseNumberChange($event, 20, 'unuseTwentyMoney')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyMoney.toFixed(2) }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyMoney"
                  :step="0"
                  :precision="2"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyCheckNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyCheckNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseCheckNumberChange($event, 'twenty')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyDiffNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseTwentyDiffNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseTwentyDiffReason }}</span>
                <el-input
                  v-else
                  type="textarea"
                  v-model="reportData.unuseTwentyDiffReason"
                  placeholder="请输入备注"
                  :disabled="readonly"
                />
              </td>
            </tr>
            <tr>
              <td class="bold center" height="79">50 元</td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyDispatchNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyDispatchNumber"
                  :min="0"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleDeployCompleteNumberCalculate($event, 'fiftiy')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyDeployNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyDeployNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
	       <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyDeployCompleteNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyDeployCompleteNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseNumberChange($event, 50, 'unuseFiftiyMoney')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyMoney.toFixed(2) }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyMoney"
                  :step="0"
                  :precision="2"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyCheckNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyCheckNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseCheckNumberChange($event, 'fiftiy')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyDiffNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseFiftiyDiffNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseFiftiyDiffReason }}</span>
                <el-input
                  v-else
                  type="textarea"
                  v-model="reportData.unuseFiftiyDiffReason"
                  placeholder="请输入备注"
                  :disabled="readonly"
                />
              </td>
            </tr>
            <tr>
              <td class="bold center" height="79">100 元</td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredDispatchNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredDispatchNumber"
                  :min="0"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleDeployCompleteNumberCalculate($event, 'hundred')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredDeployNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredDeployNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
	       <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredDeployCompleteNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredDeployCompleteNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseNumberChange($event, 100, 'unuseHundredMoney')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredMoney.toFixed(2) }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredMoney"
                  :step="0"
                  :precision="2"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredCheckNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredCheckNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  @change="handleUnuseCheckNumberChange($event, 'hundred')"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredDiffNumber }}</span>
                <el-input-number
                  v-else
                  class="input-number"
                  v-model="reportData.unuseHundredDiffNumber"
                  :step="0"
                  :precision="0"
                  :controls="false"
                  :disabled="true"
                />
              </td>
              <td class="center">
                <span v-if="readonly">{{ reportData.unuseHundredDiffReason }}</span>
                <el-input
                  v-else
                  type="textarea"
                  v-model="reportData.unuseHundredDiffReason"
                  placeholder="请输入备注"
                  :disabled="readonly"
                />
              </td>
            </tr>
            <tr>
              <td class="bold center">备注</td>
              <td colspan="13" class="center" height="79">
                <span v-if="readonly">{{ reportData.otherRemark }}</span>
                <el-input
                  v-else
                  type="textarea"
                  v-model="reportData.otherRemark"
                  placeholder="请输入备注"
                  :disabled="readonly"
                />
              </td>
            </tr>
            <tr>
              <td colspan="3" class="bold center">盘点人</td>
              <td colspan="4" class="center" height="61">
                <span v-if="readonly">{{ reportData.checkPersonName }}</span>
                <el-select
                  v-else
                  v-model="reportData.checkPersonName"
                  placeholder=""
                  style="width: 100%"
                  @change="changeCheckPersonName"
                  clearable
                  filterable
                  :disabled="readonly"
                >
                  <el-option
                    v-for="(item, index) in userNames"
                    :key="index"
                    :label="item.nikename"
                    :value="item.nikename"
                  >
                  </el-option>
                </el-select>
              </td>
              <td colspan="2" class="bold center">盘点人工号</td>
              <td colspan="3" class="center" height="61">
                <span v-if="readonly">{{ reportData.checkPersonJobNo }}</span>
                <el-select
                  v-else
                  v-model="reportData.checkPersonJobNo"
                  placeholder=""
                  style="width: 100%"
                  clearable
                  filterable
                  :disabled="readonly"
                >
                  <el-option
                    v-for="(item, index) in userJobNos"
                    :key="index"
                    :label="item.userCode"
                    :value="item.userCode"
                  >
                  </el-option>
                </el-select>
              </td>
            </tr>
            <tr>
              <td colspan="3" class="bold center">复核人</td>
              <td colspan="4" class="center" height="61">
                <span v-if="readonly">{{ reportData.attendName }}</span>
                <el-select
                  v-else
                  v-model="reportData.attendName"
                  placeholder=""
                  style="width: 100%"
                  @change="changeAttendName"
                  clearable
                  filterable
                  :disabled="readonly"
                >
                  <el-option
                    v-for="(item, index) in userNames"
                    :key="index"
                    :label="item.nikename"
                    :value="item.nikename"
                  >
                  </el-option>
                </el-select>
              </td>
              <td colspan="2" class="bold center">复核人工号</td>
              <td colspan="3" class="center" height="61">
                <span v-if="readonly">{{ reportData.attendJobNo }}</span>
                <el-select
                  v-else
                  v-model="reportData.attendJobNo"
                  placeholder=""
                  style="width: 100%"
                  clearable
                  filterable
                  :disabled="readonly"
                >
                  <el-option
                    v-for="(item, index) in userJobNos"
                    :key="index"
                    :label="item.userCode"
                    :value="item.userCode"
                  >
                  </el-option>
                </el-select>
              </td>
            </tr>
          </table>
          <div class="submit-content">
            <el-button v-if="!readonly" type="primary" size="small" @click="saveOrUpdate">保存</el-button>
            <el-button size="small" @click="handleCancel">取消</el-button>
          </div>
        </el-form>
      </div>
    </basic-container>
  </div>
</template>

<script>
import { dateFormat } from "@/util/date";
import { getSysUserToRevenue } from "@/api/admin/user";
import { saveOrUpdate, getInvoiceCatCheck, getTypeValue, getPreviousMonthInvoiceCatCheck } from "@/api/subwaystm/swstinvoicecatcheck";

export default {
  name: "invoicecatCheckAdd",
  props: {
    reportData: {
      type: Object,
      default: () => {
        return {};
      }
    },
    operationType: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      dateFormat: dateFormat,
      initialStatisticsDate: '',
      checkDay: '25',
      userNames: [],
      userJobNos: []
    };
  },
  created() {
    this.getPassenger();
    getTypeValue('pettymoney_check_day').then(response => {
      this.checkDay = response.data.data[0].value;
	  });
  },
  mounted () {
    if(this.operationType == 'add'){
      this.initialStatisticsDate = new Date();
      this.statisticsDateSelect(dateFormat(this.initialStatisticsDate).substr(0, 7));
    }

  },
  computed: {
    readonly(){
      return this.operationType === 'view';
    }
  },
  filters: {
    formatDate(value) {
      if (!value) return '';
      // 格式化日期
      return dateFormat(new Date(value)).substr(0, 7);
    }
  },
  methods: {
    // 计算调配完数量
    handleDeployCompleteNumberCalculate(value, field) {
      if (!isNaN(value)) {
        if (field == 'ten') {
          this.reportData.unuseTenDeployCompleteNumber = this.reportData.unuseTenBalanceNumber + this.reportData.unuseTenDispatchNumber + this.reportData.unuseTenDeployNumber;
        } else if (field == 'twenty') {
          this.reportData.unuseTwentyDeployCompleteNumber = this.reportData.unuseTwentyBalanceNumber + this.reportData.unuseTwentyDispatchNumber + this.reportData.unuseTwentyDeployNumber;
        } else if (field == 'fiftiy') {
          this.reportData.unuseFiftiyDeployCompleteNumber = this.reportData.unuseFiftiyBalanceNumber + this.reportData.unuseFiftiyDispatchNumber + this.reportData.unuseFiftiyDeployNumber;
        } else if (field == 'hundred') {
          this.reportData.unuseHundredDeployCompleteNumber = this.reportData.unuseHundredBalanceNumber + this.reportData.unuseHundredDispatchNumber + this.reportData.unuseHundredDeployNumber;
        }
      }
    },
    // 计算金额合计和差异数量
    handleUnuseNumberChange(value, amount, field) {
      if (!isNaN(value)) {
        this.reportData[field] = value * amount;
        if (field == 'unuseTenMoney') {
          this.reportData.unuseTenDiffNumber = this.reportData.unuseTenCheckNumber - value;
        } else if (field == 'unuseTwentyMoney') {
          this.reportData.unuseTwentyDiffNumber = this.reportData.unuseTwentyCheckNumber - value;
        } else if (field == 'unuseFiftiyMoney') {
          this.reportData.unuseFiftiyDiffNumber = this.reportData.unuseFiftiyCheckNumber - value;
        } else if (field == 'unuseHundredMoney') {
          this.reportData.unuseHundredDiffNumber = this.reportData.unuseHundredCheckNumber - value;
        }
      }
    },
    // 计算差异数量
    handleUnuseCheckNumberChange(value, field) {
      if (!isNaN(value)) {
        if (field == 'ten') {
          this.reportData.unuseTenDiffNumber = value - this.reportData.unuseTenNumber;
        } else if (field == 'twenty') {
          this.reportData.unuseTwentyDiffNumber = value - this.reportData.unuseTwentyNumber;
        } else if (field == 'fiftiy') {
          this.reportData.unuseFiftiyDiffNumber = value - this.reportData.unuseFiftiyNumber;
        } else if (field == 'hundred') {
          this.reportData.unuseHundredDiffNumber = value - this.reportData.unuseHundredNumber;
        }
      }
    },
    // 设置盘点日期（yyyy-mm-dd）
    statisticsDateSelect(val) {
      this.reportData.statisticsDate = val + '-' + this.checkDay;
      if(this.operationType === 'add'){
        this.getPreviousMonthData(val)
      }
    },
    getPreviousMonthData(val) {
      getPreviousMonthInvoiceCatCheck(val)
        .then(response => {
          const result = response.data.data;
          if(!result) {
            this.$set(this.reportData, 'unuseTenBalanceNumber', 0);
            this.$set(this.reportData, 'unuseTwentyBalanceNumber', 0);
            this.$set(this.reportData, 'unuseFiftiyBalanceNumber', 0);
            this.$set(this.reportData, 'unuseHundredBalanceNumber', 0);
          } else {
            this.$set(this.reportData, 'unuseTenBalanceNumber', result.unuseTenBalanceNumber || 0);
            this.$set(this.reportData, 'unuseTwentyBalanceNumber', result.unuseTwentyBalanceNumber || 0);
            this.$set(this.reportData, 'unuseFiftiyBalanceNumber', result.unuseFiftiyBalanceNumber || 0);
            this.$set(this.reportData, 'unuseHundredBalanceNumber', result.unuseHundredBalanceNumber || 0);
            this.handleDeployCompleteNumberCalculate(this.reportData.unuseTenBalanceNumber, 'ten');
            this.handleDeployCompleteNumberCalculate(this.reportData.unuseTwentyBalanceNumber, 'twenty');
            this.handleDeployCompleteNumberCalculate(this.reportData.unuseFiftiyBalanceNumber, 'fiftiy');
            this.handleDeployCompleteNumberCalculate(this.reportData.unuseHundredBalanceNumber, 'hundred');
          }
        })
    },
    // 检查本月备用金盘点数据是否存在
    async getInvoiceCatCheck(){
      let checkData = {};
      await getInvoiceCatCheck(this.reportData.statisticsDate)
        .then(response => {
          checkData = response.data.data;
        })
      return checkData;
    },
    // 保存
    async saveOrUpdate() {
      if (this.validatenull(this.reportData.statisticsDate)) {
        this.$message.error("盘点日期不能为空！");
        return false;
      }
      if (this.operationType === 'add') {
        const checkData = await this.getInvoiceCatCheck();
        if(!this.validatenull(checkData)){
          this.$message.error("本月备用金盘点数据已存在，请勿重复录入！");
          return false;
        }
      }
      this.$confirm("确认要保存吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        saveOrUpdate(this.reportData)
          .then((data) => {
            this.$message.success("保存成功");
            this.handleCancel();
          })
          .catch(() => {
            this.$message.error("保存失败！");
          });
      });
    },
    // 取消
    handleCancel() {
      this.$emit('closed');
    },
    // 获取车站人员
    getPassenger() {
      getSysUserToRevenue().then((response) => {
        this.userNames = response.data.data;
        this.userJobNos = response.data.data;
      });
    },
    // 盘点人选择
    changeCheckPersonName(data) {
      var objVal = {};
      this.userJobNos.forEach((val) => {
        if (val.nikename == data) {
          objVal = val;
        }
      });
      this.reportData.checkPersonJobNo = objVal.userCode;
    },
    // 复核人选择
    changeAttendName(data) {
      var objVal = {};
      this.userJobNos.forEach((val) => {
        if (val.nikename == data) {
          objVal = val;
        }
      });
      this.reportData.attendJobNo = objVal.userCode;
    },
  },
};
</script>
<style lang="scss">
.sw-revenue-daily-report {
  .input-number {
    width: 100%;
  }
  table {
    border: #b7babf solid 1px;
    border-top: none;
    width: 100%;
    td {
      padding: 12px 10px;
      border: #b7babf solid 1px;
    }
  }
  .center {
    text-align: center;
  }
  .bold {
    font-weight: bold;
  }
  .submit-content {
    padding-top: 30px;
    text-align: center;
  }
}
</style>
